![]() ![]() |
Q: We need a handle to a pop-up menu in a dialog so that we can dynamically change its items. I tried to set the menu ID to -12345 and stuff a dynamically allocated menu handle into the pop-up control's "private" data field, but this menu does not appear. Please advise. I have also had problems with disposing a dialog which contains a pop-up menu control if there are other instances of the same dialog, because disposing the first dialog disposes the menu handle, and the other dialogs can no longer use it. I've attempted (without success) to circumvent this by NULLing the menu reference in the control prior to disposing the dialog. Does the control create another reference to the menu I am unable to get at? Is there any way around this issue? Basically, how do I retain my reference to my menu after closing the window?
P.S. I need solutions that work regardless of whether the Appearance extension is installed. A: Your question reads as if you are having a number of problems. Fortunately, there is only one. Here is some little-known wisdom regarding the pop-up menu CDEFs (both popupMenuProc and kControlPopupButtonProc):
What should you do instead?
How and why does this help? The pop-up menu CDEFs look in two places for the menu you specify.
We recommend you always make sure the CDEFs can find the menus they want in the menu list by using the numbered steps listed above. If you don't follow these steps, the CDEFs will create and manage the menus, the problems you describe will crop up, and things will get tedious very quickly. The only time you want to allow the CDEFs to create a menu is when you know the menu will only be used in a single (optimally moveable) modal dialog. If you'd rather not keep this exception in mind, just follow the numbered steps; they always work. By the way, yes, the CDEFs do cache a reference to the menu in a
place other than their "private" control data, so changing that data
will not help. In fact, altering system data structures is a good
thing to avoid in general. Read when you must, but don't ever write
if you can possibly avoid it. Also, take a look at what the
Mac OS 8 Control Manager
has to say about the
Pop-Up Menu Private Structure( [Jul 30 1998] |
Developer Documentation | Technical Notes | Development Kits | Sample Code |